<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------

namespace Admin\Model;
use Think\Model;

/**
 * 商品模型
 * @author huajie <banhuajie@163.com>
 */

class StoreModel extends Model {

    /* 自动验证规则 */
    protected $_validate = array(
        array('url', 'url', 'URL格式不正确', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
        array('short', 'url', 'URL格式不正确', self::VALUE_VALIDATE, 'regex', self::MODEL_BOTH),
    );

    /* 自动完成规则 */
    protected $_auto = array(
        array('status', 1, self::MODEL_INSERT, 'string'),
        array('create_time', 'time', self::MODEL_BOTH, 'function'),
    );
   
    public function lists($pages=8,$order='id DESC'){

            $count = $this->count();//获取符合条件的数据总数count

            $page=new \Think\Page($count, $pages);

            $list=$this->order($order)->limit($page->firstRow.','.$page->listRows)->select();

            $page->setConfig('prev', "上一页");//上一页

            $page->setConfig('next', '下一页');//下一页

            $page->setConfig('first', '<<');//第一页

            $page->setConfig('last', '>>');//最后一页

            $page->setConfig( 'theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');

            $data=array(
                
            '_page'=>$page->show(),

            'data'=>$list,

    );
            return $data;       
    }
   
}
